package com.ibeeking.found.report.rest.controller.v1;

import com.ibeeking.found.report.rest.service.IBaseService;
import com.ibeeking.found.report.rest.service.IReportFileService;
import com.ibeeking.found.report.service.common.dos.ReportFileDO;
import com.ibeeking.found.report.service.common.po.ResponseBean;
import com.ibeeking.found.report.service.common.query.ReportFilePageQuery;
import com.ibeeking.found.report.service.common.vo.ReportFileVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * (ReportFileDO)实体类
 *
 * @author peiyanni
 * @since 2021-02-18 14:48:33
 */
@RestController
@RequestMapping("/reportFile/v1")
public class DmpReportFileController extends DmpBaseController<ReportFilePageQuery, ReportFileDO, ReportFileVO> {

    @Resource
    private IReportFileService reportFileServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "上传报表")
    @PostMapping("/upload")
    public ResponseBean upload(@RequestParam("file") MultipartFile file) {
        return ResponseBean.builder().message("success").data((reportFileServiceImpl.upload(file))).build();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "下载报表")
    @GetMapping(value = "/download/{fileId}")
    public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response, @PathVariable("fileId") String fileId) {
        return reportFileServiceImpl.download(request, response, fileId);
    }

    /**
     * 获取实际服务类
     *
     * @return
     */
    @Override
    public IBaseService<ReportFilePageQuery, ReportFileDO> getService() {
        return reportFileServiceImpl;
    }

    /**
     * 获取当前Controller数据库实体Entity
     *
     * @return
     */
    @Override
    public ReportFileDO getEntity() {
        return new ReportFileDO();
    }

    /**
     * 获取当前Controller数据传输DTO
     *
     * @return
     */
    @Override
    public ReportFileVO getDTO() {
        return new ReportFileVO();
    }
}
